﻿@model Nop.Web.Models.ShoppingCart.ShoppingCartModel
@using Nop.Core.Domain.Orders
@using Nop.Web.Framework;
<div class="order-summary-content">
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="message-error">
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    @Model.Warnings[i]
                   if (i != Model.Warnings.Count - 1)
                   {
                        <br />
                   }
                }
        </div>
        }
        @*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
        <table class="cart">
            @if (Model.IsEditable)
            {
                <col width="1" />
            }
            @if (Model.ShowSku)
            {
                <col width="1" />
            }
            @if (Model.ShowProductImages)
            {
                <col width="1" />
            }
            <col />
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <thead>
                <tr class="cart-header-row">
                    @if (Model.IsEditable)
                    {
                        <th>
                            @T("ShoppingCart.Remove")
                        </th>
                    }
                    @if (Model.ShowSku)
                    {
                        <th>
                            @T("ShoppingCart.SKU")
                        </th>
                    }
                    @if (Model.ShowProductImages)
                    {
                        <th class="picture">
                        </th>
                    }
                    <th>
                        @T("ShoppingCart.Product(s)")
                    </th>
                    <th>
                        @T("ShoppingCart.UnitPrice")
                    </th>
                    <th>
                        @T("ShoppingCart.Quantity")
                    </th>
                    <th class="end">
                        @T("ShoppingCart.ItemTotal")
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr class="cart-item-row">
                        @if (Model.IsEditable)
                        {
                            <td>
                                <input id="removefromcart" type="checkbox" name="removefromcart" value="@(item.Id)" />
                            </td>
                        }
                        @if (Model.ShowSku)
                        {
                            <td class="nobr">
                                @item.Sku
                            </td>
                        }
                        @if (Model.ShowProductImages)
                        {
                            <td class="productpicture">
                                <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                            </td>
                        }
                        <td class="product">
                            <a href="@Url.RouteUrl("Product", new { productId = item.ProductId, SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
                            @if (!String.IsNullOrEmpty(item.AttributeInfo))
                            {
                                <br />
                                @Html.Raw(item.AttributeInfo)
                            }
                            @if (!String.IsNullOrEmpty(item.RecurringInfo))
                            {
                                <br />
                                @Html.Raw(item.RecurringInfo)
                            }
                            @if (item.Warnings.Count > 0)
                            {
                                <div class="message-error">
                                        @for (int i = 0; i < item.Warnings.Count; i++)
                                        {
                                            @item.Warnings[i]
                                            if (i != item.Warnings.Count - 1)
                                            {
                                                <br />
                                            }
                                        }
                                </div>
                            }
                        </td>
                        <td class="nobr">
                            <span class="productPrice">@item.UnitPrice</span>
                        </td>
                        <td class="nobr">
                            @if (Model.IsEditable)
                            {
                                <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" id="itemquantity@(item.Id)" class="qty-input" />
                            }
                            else
                            {
                                <span>@item.Quantity</span>
                            }
                        </td>
                        <td class="nobr end">
                            <span class="productPrice">@item.SubTotal</span>
                            @if (!String.IsNullOrEmpty(item.Discount))
                            {
                                <br />
                                @T("ShoppingCart.ItemYouSave")<text>:</text>
                                <text>&nbsp; &nbsp;</text>@item.Discount
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>                
        <div class="clear">
        </div>
                if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
        <div class="selected-checkout-attributes">
            @Html.Raw(Model.CheckoutAttributeInfo)
        </div>
        <div class="clear">
        </div>
                }
        <div>
            @if (Model.IsEditable)
            {
                <div class="common-buttons">
                    <input type="submit" name="updatecart" value="@T("ShoppingCart.UpdateCart")" id="updatecart" class="updatecartbutton" />
                    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" id="continueshopping" class="continueshoppingbutton" />
                    <input type="submit" name="startcheckout" value="startcheckout" id="startcheckout"
                        style="display: none;" />
                </div>                    
                <div class="clear">
                </div>
                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
                <div class="clear">
                </div>
            }
        </div>
        <div class="clear">
        </div>
        }
        <div class="cart-footer">
            @if (Model.IsEditable)
            {
                if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                {
                <div>
                    <div class="min-amount-warning">
                        @Model.MinOrderSubtotalWarning
                    </div>
                </div>
                }
            }
            <div class="clear">
            </div>
            <div class="totals">
                @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                @if (Model.IsEditable)
                {
                    <div class="clear">
                    </div>
                    if (Model.TermsOfServiceEnabled)
                    {
                    <script language="javascript" type="text/javascript">
                        function accepttermsofservice() {
                            if (!document.getElementById('termsofservice').checked) {
                                alert('@T("Checkout.TermsOfService.PleaseAccept")');
                                return false;
                            }
                            else
                                return true;
                        }
                    </script>
                    <div class="terms-of-service">
                        <input id="termsofservice" type="checkbox" name="termsofservice" />
                        @T("Checkout.TermsOfService.IAccept")
                        @*uncomment below to how simple pop-up*@
                        @*<span class="read" onclick="javascript:OpenWindow('@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofUse" })', 450, 500, true)">@T("Checkout.TermsOfService.Read")</span>*@
                        
                        @*use fancybox to how nice pop-up*@
                        @{
                        Html.AddScriptParts(@Url.Content("~/Scripts/jquery.fancybox-1.3.4.pack.js"));
                        Html.AddCssFileParts(@Url.Content("~/Content/fancybox/jquery.fancybox-1.3.4.css"));
                            }
                            <a class="read" href='@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofUse" })'>@T("Checkout.TermsOfService.Read")</a>
                            <script type="text/javascript">
                                $(".terms-of-service .read").fancybox({
                                    'speedIn': 600,
                                    'speedOut': 200,
                                    'width': 450,
                                    'height': 500,
                                    'type': 'iframe',
                                    'centerOnScroll': true
                                });
                            </script>
                    </div>
                    }
                            
                    <div class="clear">
                    </div>
                    <div class="checkout-buttons">
                        @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <script language="javascript" type="text/javascript">
                                        function startcheckout() {
                                            //terms of services
                                            var termOfServiceOk = true;
                                            @if (Model.TermsOfServiceEnabled)
                                            {
                                                <text>
                                                termOfServiceOk = accepttermsofservice();
                                                </text>
                                            }
                                            if (termOfServiceOk)
                                            {
                                                $('#startcheckout').trigger("click");
                                            }
                                        }
                            </script>
                            <input type="submit" name="checkout" value="@T("Checkout")" id="checkout" class="checkoutbutton" onclick="startcheckout()" />
                        }
                    </div>
                    <div class="addon-buttons">
                        @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                        @if (Model.ButtonPaymentMethodActionNames != null && Model.ButtonPaymentMethodActionNames.Count > 0)
                        {
                            for (int i = 0; i < Model.ButtonPaymentMethodActionNames.Count; i++)
                            {
                                @Html.Action(Model.ButtonPaymentMethodActionNames[i], Model.ButtonPaymentMethodControllerNames[i], Model.ButtonPaymentMethodRouteValues[i])
                            }
                        }
                    </div>
                }
            </div>
            <div class="cart-collaterals">
                @if (Model.IsEditable)
                {
                    <div class="deals">
                        @if (Model.ShowDiscountBox)
                        {
                            using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post))
                            {
                            <div class="coupon-box">
                                <b>@T("ShoppingCart.DiscountCouponCode")</b>
                                <br />@T("ShoppingCart.DiscountCouponCode.Tooltip")<br />
                                <input name="discountcouponcode" type="text" id="discountcouponcode" class="discountcouponcode" />&nbsp;
                                <input type="submit" name="applydiscountcouponcode" value="@T("ShoppingCart.DiscountCouponCode.Button")" id="applydiscountcouponcode" class="applycouponcodebutton" />
                                @if (!String.IsNullOrEmpty(Model.DiscountMessage))
                                {
                                    <div class="clear"></div>
                                    <div class="message-error">
                                        @Model.DiscountMessage
                                    </div>
                                }
                                @if (!String.IsNullOrEmpty(Model.CurrentDiscountCode))
                                {
                                    <div class="clear">
                                    </div>
                                    <div class="current-code">
                                        <br />
                                        @string.Format(T("ShoppingCart.DiscountCouponCode.CurrentCode").Text, Model.CurrentDiscountCode)
                                        @*empty value (little hack for FormValueExistsAttribute)*@
                                        <input id="removediscountcouponcode" type="submit" name="removediscountcouponcode" value=" " title="@T("Common.Remove")" class="removediscountbutton" />
                                    </div>
                                }                                
                            </div>
                            }
                        }
                        @if (Model.ShowGiftCardBox)
                        {
                            using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post))
                            {
                            <div class="giftcard-box">
                                <b>@T("ShoppingCart.GiftCardCouponCode")</b>
                                <br />@T("ShoppingCart.GiftCardCouponCode.Tooltip")<br />
                                <input name="giftcardcouponcode" type="text" id="giftcardcouponcode" class="giftcardcouponcode" />&nbsp;
                                <input type="submit" name="applygiftcardcouponcode" value="@T("ShoppingCart.GiftCardCouponCode.Button")" id="applygiftcardcouponcode" class="applycouponcodebutton" />
                                @if (!String.IsNullOrEmpty(Model.GiftCardMessage))
                                {
                                    <div class="clear"></div>
                                    <div class="message-error">
                                        @Model.GiftCardMessage
                                    </div>
                                }
                            </div>
                            }
                        }
                    </div>
                    @Html.Partial("EstimateShipping", Model.EstimateShipping)
                }
            </div>
            <div class="clear">
            </div>
            @Html.Action("CrossSellProducts", "Catalog")
        </div>
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
</div>
